package com.example.myapplication.viewpager;

import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import com.example.myapplication.R;

public class ViewPagerActivity extends AppCompatActivity {

    private Carousel carousel;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_view_pager);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.pager), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        Carousel carousel = new Carousel(this, findViewById(R.id.index_dot), findViewById(R.id.viewPager2));
        int[] ids = new int[] {
                R.drawable.ikun1,
                R.drawable.ikun2,
                R.drawable.ikun3,
                R.drawable.ikun4,
        };

        carousel.initViews(ids);
        carousel.startAutoScroll();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        carousel.stopAutoScroll();
    }
}